﻿$(document).ready(function () {
    page.init();

    $("#" + page.userNameId).search({
        title: "",
        tip: "",
        type: "email",
        maxTipLength: 25,
        emailChooseFun: function (_val) {
            if (_val && _val != "") {
                $("#" + page.userNameId).val(_val);
                $("#jquery-search").hide().html("");
                $("#" + page.passwordId).focus();
            }
        },
        searchItems: ["{0}", "{0}@qq.com", "{0}@gmail.com", "{0}@vip.sina.com", "{0}@sina.com", "{0}@hotmail.com", "{0}@yahoo.com.cn", "{0}@sohu.com", "{0}@163.com", "{0}@126.com"]
    });
});

var page = {
    tip: "<div style='width: 233px; display:none;' class='layer_form_tips' node-type='outer'><div class='bg'><div class='content' node-type='inner'><a class='W_ico12 icon_close' onclick='return false;' node-type='close' action-type='common_layer_errtip_close' href='#'></a><p class='tips' node-type='msg'></p></div><div class='arrow arrow_tips' node-type='arrow' style='left: 85px;'></div></div></div>",

    init: function () {
        $(page.tip).appendTo(document.body);
        $(".icon_close").click(function () {
            $(".layer_form_tips").hide();
        });

        $(".W_login_form input.W_input").each(function () {
            if ($(this).val() != "")
                $(this).next().hide();
            else
                $(this).next().show();
        });

        $(".W_login_form input.W_input").focus(function () {
            $(this).parent().addClass("W_input_focus2");
            $(this).parent().find("span").hide();
        }).blur(function () {
            $(this).parent().removeClass("W_input_focus2");
            if ($(this).parent().find("input").val() == "")
                $(this).parent().find("span").show();
        });

        $(".inp span").click(function () {
            $(this).hide();
            $(this).parent().find("input").focus();
        });
    },

    checkLogin: function () {
        $(".layer_form_tips").hide();
        if ($("#" + page.userNameId).val() == "") {
            page.showTips("请输入用户名");
            return false;
        }
        else if ($("#" + page.passwordId).val() == "") {
            page.showTips("请输入密码", $("#" + page.passwordId));
            return false;
        }
        else if ($("#" + page.checkCodeId).val() == "") {
            page.showTips("请输入验证码", $("#" + page.checkCodeId));
            return false;
        }
        else
            return true;
    },

    showTips: function (tip, obj) {
        obj = obj || $("#" + page.userNameId);
        var offset = $(obj).offset();
        var parent = $(obj).parent();
        $(".layer_form_tips .tips").html(tip);
        $(".layer_form_tips").css({ "top": offset.top - 34, "left": parent.offset().left }).show();
    }
};
